﻿// LightNet - Lightweight .NET Framework
// Copyright (c) 2010 http://lightnet.codeplex.com

namespace System.Runtime.CompilerServices
{
    using System.Security;

    /// <summary>
    /// Provides a set of static methods and properties that provide support for compilers. This class cannot be inherited.
    /// </summary>
    public static class RuntimeHelpers
    {
        /// <summary>
        /// Serves as a hash function for a particular type, suitable for use in hashing algorithms and data structures such as a hash table.
        /// </summary>
        /// <param name="o">An <see cref="T:System.Object" /> to retrieve the hash code for.</param>
        /// <returns>A hash code for the <see cref="T:System.Object" /> identified by the <paramref name="o" /> parameter.</returns>
        [MethodImpl(MethodImplOptions.InternalCall), SecuritySafeCritical]
        public static extern int GetHashCode(object o);

        /// <summary>
        /// Boxes a value type.
        /// </summary>
        /// <param name="obj">The value type to be boxed.</param>
        /// <returns>Returns a boxed copy of <paramref name="obj" /> if it is a value class; otherwise <paramref name="obj" /> itself is returned.</returns>
        [MethodImpl(MethodImplOptions.InternalCall), SecuritySafeCritical]
        public static extern object GetObjectValue(object obj);

        /// <summary>
        /// Provides a fast way to initialize an array from data stored in a module.
        /// </summary>
        /// <param name="array">The array to be initialized.</param>
        /// <param name="fldHandle">A <see cref="T:System.RuntimeFieldHandle" /> specifying the location of the data used to initialize the array.</param>
        [MethodImpl(MethodImplOptions.InternalCall), SecuritySafeCritical]
        public static extern void InitializeArray(Array array, RuntimeFieldHandle fldHandle);

        /// <summary>
        /// Gets the offset in bytes to the data in the given string.
        /// </summary>
        /// <returns>The byte offset, from the start of the <see cref="T:System.String" /> object to the first character in the string.</returns>
        public static int OffsetToStringData { get { return 8; } }

        [MethodImpl(MethodImplOptions.InternalCall), SecuritySafeCritical]
        new internal static extern bool Equals(object o1, object o2);
    }
}
